home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Offline Browsing / HTTrack.exe / data1.cab / Sources / lib / example.c next >
Encoding:
C/C++ Source or Header  |  2001-04-28  |  3.7 KB  |  132 lines

  1. /*
  2.     HTTrack library example
  3.  
  4.     To Build on Windows:
  5.     - compile everything in src/ BUT htsparse.c, compile httracklib.c and example.c
  6.     - multithreaded
  7.     - no precompiled headers with VC
  8.  
  9.     To Build on Linux:
  10.     make lib_linux (or "make lib_netbsd", or "make lib_default" and so on)
  11.     cp htssystem.h src/htssystem.h
  12.     make build_httracklib
  13. */
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "httracklib.h"
  19.  
  20. /*
  21.  * Name:           main
  22.  * Description:    main() function
  23.  * Parameters:     None
  24.  * Should return:  error status
  25. */
  26. int main(void) {
  27.   /* 
  28.      First, ask for an URL 
  29.      Note: For the test, option r2 (mirror max depth=1) and --testscan (no index, no cache, do not store, no log files)
  30.   */
  31.   char _argv[][256] = {"httrack_test" , "<URL>" , "-r2" , "--testscan" , ""  };
  32.   char* argv[]      = {NULL           , NULL    , NULL  , NULL        , NULL};
  33.   int         argc = 0;
  34.   while(strlen(_argv[argc])) {
  35.     argv[argc]=_argv[argc];
  36.     argc++;
  37.   }
  38.   argv[argc]=NULL;
  39.   printf("HTTrackLib test program\n");
  40.   printf("Enter URL (example: www.foobar.com/index.html) :");
  41.   scanf("%s",argv[1]);
  42.   printf("Test: 1 depth\n");
  43.  
  44.   /* Then, launch the mirror */
  45.   HTTrackLib_main(argc,argv);
  46.  
  47.   /* Wait for a key */
  48.   printf("\nPress ENTER key to exit\n");
  49.   scanf("%s",argv[1]);
  50.  
  51.   /* That's all! */
  52.   return 0;
  53. }
  54.  
  55. /*
  56.  * Name:           HTTrackLib_Init
  57.  * Description:    Called during HTTrack initialization
  58.  * Parameters:     None
  59.  * Should return:  Nothing
  60. */
  61. void HTTrackLib_Init() {
  62.   printf("HTTrack initialized\n");
  63. }
  64.  
  65. /*
  66.  * Name:           HTTrackLib_Close
  67.  * Description:    Called during HTTrack termination
  68.  * Parameters:     None
  69.  * Should return:  Nothing
  70. */
  71. void HTTrackLib_Close() {
  72.   printf("HTTrack closed\n");
  73. }
  74.  
  75. /*
  76.  * Name:           HTTrackLib_Start
  77.  * Description:    Called before HTTrack starts the mirror
  78.  * Parameters:     None
  79.  * Should return:  1 if no error has been detected
  80. */
  81. int HTTrackLib_Start() {
  82.   printf("HTTrack started\n");
  83.   return 1; 
  84. }
  85.  
  86. /*
  87.  * Name:           HTTrackLib_End
  88.  * Description:    Called after HTTrack ends the mirror
  89.  * Parameters:     None
  90.  * Should return:  1 if no error has been detected
  91. */
  92. int HTTrackLib_End() { 
  93.   printf("HTTrack ended\n");
  94.   return 1; 
  95. }
  96.  
  97. /*
  98.  * Name:           HTTrackLib_TestLink
  99.  * Description:    Test if a link has to be caught
  100.  * Parameters:     host_name (host name, www.foo.com)
  101.  *                 filename (filename, /index.html)
  102.  *                 current_status
  103.  *                   0: link should be accepted
  104.  *                   1: link should be refused
  105.  *                  -1: the engine has no opinion (by default, the link will be refused)
  106.  * Should return:  new status
  107.  *                   0: link will be accepted
  108.  *                   1: link will be refused
  109.  *                  -1: we do not have any opinion (by default, current status will be kept)
  110. */
  111. int HTTrackLib_TestLink(char* host_name,char* filename,int current_status) {
  112.   printf("HTTrack asked for status for this link link: %s%s (current is %s)\n",host_name,filename,(current_status==0)?"accepted":"refused");
  113.   return -1;
  114. }
  115.  
  116. /*
  117.  * Name:           HTTrackLib_TestParse
  118.  * Description:    Test if an HTML file has to be parsed (after download)
  119.  * Parameters:     host_name (host name, www.foo.com)
  120.  *                 filename (filename, /index.html)
  121.  *                 buffer_html (address of the HTML buffer)
  122.  *                 buffer_html_size (size of this buffer in bytes)
  123.  * Should return:  response
  124.  *                   0: do not parse this file
  125.  *                   1: parse this file (default behaviour)
  126. */
  127. int HTTrackLib_TestParse(char* host_name,char* filename,char* buffer_html,int buffer_html_size) {
  128.   printf("HTTrack asks whether to parse %s%s (%d bytes)\n",host_name,filename,buffer_html_size);
  129.   return 1;
  130. }
  131.  
  132.